﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;

namespace PandocWrapper
{
    public class PandocOptions
    {
            
    }

    public class PandocWrapper
    {
        public PandocWrapper() { }


        public void ShellExecuteBrowser(string href)
        {
            System.Diagnostics.Process.Start(href);
        }

        public string Convert(string source, string input, string output)
        {
            string processName = @"C:\Program Files\Pandoc\bin\pandoc.exe";
            string args = String.Format(@"-r {0} -t {1}", input, output);// + input + " -t " + output );

            ProcessStartInfo psi = new ProcessStartInfo(processName, args);

            psi.RedirectStandardOutput = true;
            psi.RedirectStandardInput = true;

            Process p = new Process();
            p.StartInfo = psi;
            psi.UseShellExecute = false;
            p.Start();

            string outputString = "";
            byte[] inputBuffer = ASCIIEncoding.UTF8.GetBytes(source);
            p.StandardInput.BaseStream.Write(inputBuffer, 0, inputBuffer.Length);
            p.StandardInput.Close();

            using (System.IO.StreamReader sr = new System.IO.StreamReader(p.StandardOutput.BaseStream))
            {
            	
                outputString = sr.ReadToEnd();
            }
            

            return outputString;
        }
    }
}
